<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="!crud.props.searchToggle">
        <el-form size="small" label-width="70px" v-formkey="{query:crud.toQuery}">
          <el-row :gutter="10" style="margin-bottom: 10px">
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="银行">
                <el-input v-model="query.keyword" placeholder="请输入银行名称"></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="所属部门">
                <treeselect
                  v-model="query.deptId"
                  :options="depts"
                  placeholder="选择部门"
                  :normalizer="normalizer"
                >
                </treeselect>
              </el-form-item>
            </el-col>
            <el-col :span="12" align="center">
              <rrOperation :crud="crud"/>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <!--表格渲染-->
      <el-table ref="table"
                @row-click="crud.selectRow"
                :row-style="crud.rowClass"
                :row-class-name="crud.tableRowClassName"
                border v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;"
                @row-dblclick="crud.toDetailPlus('financeBankBalanceDetail',$event.bankId)"
                @selection-change="crud.selectionChangeHandler">
        <el-table-column :render-header="crud.renderHeader" type="selection" width="60"/>
        <el-table-column :render-header="crud.renderHeader" type="index" width="60" label="序号"/>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('bankName')" prop="bankName"
                         label="银行名称"/>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('bankOpenBranch')"
                         prop="bankOpenBranch" label="银行支行"/>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('bankAccount')" prop="bankAccount"
                         label="银行账户"/>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('balanceAmount')" prop="balanceAmount"
                         label="余额"/>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('deptName')" prop="deptName"
                         label="所属部门"/>
        <!--        <el-table-column :render-header="crud.renderHeader" v-permission="['admin','financeBankBalance:edit','financeBankBalance:del']" label="操作"-->
        <!--                         width="150px" align="center">-->
        <!--          <template slot-scope="scope">-->
        <!--            <udOperation-->
        <!--              :data="scope.row"-->
        <!--              :permission="permission"-->
        <!--            />-->
        <!--          </template>-->
        <!--        </el-table-column>-->
      </el-table>
      <!--分页组件-->
      <pagination/>
    </div>
  </div>
</template>

<script>
import crudFinanceBankBalance from '@/api/erp/financeBankBalance'
import CRUD, {crud, form, header, presenter} from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import {getDepts} from "@/api/system/dept";
import Treeselect from '@riophae/vue-treeselect'
// crud交由presenter持有
const defaultCrud = CRUD({
  title: '银行余额',
  query: {
    keyword: null,
    deptId: null
  },
  url: 'api/financeBankBalance',
  sort: 'id,desc',
  crudMethod: {...crudFinanceBankBalance}
})
const defaultForm = {
  id: null,
  bankId: null,
  bankCode: null,
  bankName: null,
  bankAccount: null,
  bankOpenName: null,
  bankOpenBranch: null,
  balanceAmount: null,
  deptId: null,
  deptCode: null,
  deptName: null,
  userId: null,
  userCode: null,
  userName: null,
  seq: null,
  remark: null,
  createUserId: null,
  createUserCode: null,
  createUserName: null,
  createTime: null,
  updateUserId: null,
  updateUserCode: null,
  updateUserName: null,
  updateTime: null
}
export default {
  name: 'FinanceBankBalance',
  components: {pagination, crudOperation, rrOperation, udOperation, Treeselect},
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  data() {
    return {

      permission: {
        add: ['admin', 'financeBankBalance:add'],
        edit: ['admin', 'financeBankBalance:edit'],
        del: ['admin', 'financeBankBalance:del'],
        import: ['admin', 'financeBankBalance:import'],
        export: ['admin', 'financeBankBalance:export'],
        copy: ['admin', 'financeBankBalance:copy'],
        upload: ['admin', 'financeBankBalance:upload'],
        download: ['admin', 'financeBankBalance:download'],
      },
      depts: []
    }
  },
  created() {
    this.getDepts();
  },
  watch: {},
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },
    getDepts() {
      getDepts({status: 1}).then(res => {
        this.depts = res
      })
    },
    normalizer(node) {
      //去掉children=[]的children属性
      if (node.children == null || node.children.length == 0) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.name,
        children: node.children
      }
    },
  }
}
</script>

<style scoped>
.table-img {
  display: inline-block;
  text-align: center;
  background: #ccc;
  color: #fff;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  vertical-align: middle;
  width: 32px;
  height: 32px;
  line-height: 32px;
}
</style>
